package com.rockwell.maze800.model;

import org.opencv.core.Point;

public class BarrierDetector implements IDetector {

	private boolean m_present = false;
	private Point m_center;
	private float m_radius;
	
	@Override
	synchronized public void onDetect(boolean present, Point center, float radius, int height, int width) {
		if (present && radius < MIN_BARRIER_RADIUS)
			present = false;
		
		if (present && center.y < height * FOV_HEIGHT_BOUNDARY)
			present = false;
		
		if (present && center.y > height * (1 - FOV_HEIGHT_BOUNDARY))
			present = false;
		
		if (present && center.x >= width * FOV_WIDTH_BOUNDARY)
			present = false;
		
		if (!this.m_present && !present)
			return;
		
		if (this.m_present && present)
		{
			double difX = Math.abs(m_center.x - center.x);
			double difY = Math.abs(m_center.y - center.y);
			
			if (difX < 1 && difY < 1)
				return;
		}
		
		m_present = present;
		m_center = center;
		m_radius = radius;
	}
	
	@Override
	public boolean isPresent() {
		return m_present;
	}
	
	@Override
	public Point getDrift() {
		return null;
	}

	@Override
	public Point getCenter() {
		return m_center;
	}
}
